package com.bocai.freeman.view.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bocai.freeman.R;
import com.bocai.freeman.base.BaseFragment;
import com.bocai.freeman.utils.DividerItemDecoration;
import com.bocai.freeman.view.activitys.DemandDetailCommonActivity;
import com.bocai.freeman.view.activitys.DemandDetailEvaluateActivity;
import com.bocai.freeman.view.activitys.DemandDetailRefundActivity;
import com.bocai.freeman.view.adapter.OrderDemandAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by win7 on 2016/5/19.
 */
public class OrderDemandFrag extends BaseFragment {
    @Bind(R.id.rv)
    RecyclerView rv;
    private List<Integer> mData;
    private OrderDemandAdapter mOrderAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.view_all_list, null);
        ButterKnife.bind(this, view);
        initView();
        initEvent();
        return view;
    }

    @Override
    public void initEvent() {

        if (mOrderAdapter != null)
            mOrderAdapter.setOnItemClickLitener(new OrderDemandAdapter.OnItemClickLitener() {
                @Override
                public void onItemClick(View view, int position, int itemType) {
                    switch (itemType) {
                        case 1:
                            startActivity(new Intent(getActivity(), DemandDetailCommonActivity.class));
                            showToast("item:" + itemType + "position:" + position);
                            break;
                        case 2:
                            startActivity(new Intent(getActivity(), DemandDetailEvaluateActivity.class));
                            showToast("item:" + itemType + "position:" + position);
                            break;
                        case 3:
                            startActivity(new Intent(getActivity(), DemandDetailRefundActivity.class));
                            showToast("item:" + itemType + "position:" + position);
                            break;
                    }
                }
            });
    }

    private void initView() {
        mData = new ArrayList<>();
        mData.add(0);
        mData.add(1);
        mData.add(0);
        mData.add(0);
        mData.add(1);
        mData.add(0);
        mData.add(2);
        mData.add(2);
        mData.add(0);
        mData.add(0);
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        rv.setLayoutManager(manager);
        rv.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
        mOrderAdapter = new OrderDemandAdapter(mData, getActivity());
        rv.setAdapter(mOrderAdapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
